<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义弹框</title>
    <style>
        body{
            font-size: 13px;
        }
        #bg{
            width:100%;
            height: 100%;
            position: absolute;
            background-color: rgba(0,0,0,0.5);
            top: 0;
            left: 0;
            display: none;
        }
        #box{
            width: 260px;
            border: solid 0 red;
            position: absolute;
            /*z-index: 2;*/
            left: 50%;
            margin-left: -130px;
            top:50%;
            margin-top: -53px;
            display: none;
        }
        #box .title{
            background-color: #008081;
            color: white;
            padding: 5px 10px;
        }
        #box .img{
            float: left;
            margin: 13px 54px;
        }
        #box .right{
            float: left;
            margin-bottom: 10px;
            margin-top: 0;
        }
        #box>.con{
            background-color: white;
            overflow: hidden;
        }
        img{
            width: 50px;
            height: 50px;
        }
         #box>.con>.right>.btn{
            text-align: center;
         }
         #box>.con>.right>.btn>button{
             width: 62px;
             background-color:#008081;
             border: none;
         }
    </style>
</head>
<body>
    <button id="btnShow">弹出</button>
    <div id="bg"></div>
<!--定义一个弹窗-->
    <div id="box">
        <div class="title">提示</div>
        <div class="con">
            <div class="img">
                <img src="pictures/1.png" alt="">
            </div>
            <div class="right">
                <p>真的要离开了么</p>
                <div class="btn" id="close">
                    <button>确定</button>
                </div>
            </div>
        </div>
    </div>
</body>
    <script>
        var btnShow=document.getElementById("btnShow")
        var bg=document.getElementById("bg")
        var box=document.getElementById("box")
        var btn_close=document.getElementById("close")
        btnShow.onclick=function (){
            bg.style.display="block"
            box.style.display="block"
        }
        btn_close.onclick=function (){
            bg.style.display="none"
            box.style.display="none"
        }
    </script>
</html>